﻿CREATE TABLE [Membership].[UserRoles] (
    [UserId] UNIQUEIDENTIFIER NOT NULL,
    [RoleId] UNIQUEIDENTIFIER NOT NULL,
    CONSTRAINT [PK_Membership.UserRoles] PRIMARY KEY CLUSTERED ([UserId] ASC, [RoleId] ASC),
    CONSTRAINT [FK_Membership.UserRoles_Membership.Roles_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [Membership].[Roles] ([Id]) ON DELETE CASCADE,
    CONSTRAINT [FK_Membership.UserRoles_Membership.Users_UserId] FOREIGN KEY ([UserId]) REFERENCES [Membership].[Users] ([Id]) ON DELETE CASCADE
);


GO
CREATE NONCLUSTERED INDEX [IX_UserId]
    ON [Membership].[UserRoles]([UserId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_RoleId]
    ON [Membership].[UserRoles]([RoleId] ASC);

